/*
* ECARX Technology Limited is the owner of the copyright and the trade secret of this software.
* Without permission, no one has the right to obtain, disclose or use this software in any way.
*/

package ecarx.xsf.notificationcenter.sdk;


import android.app.PendingIntent;
import android.os.Bundle;
import android.os.Parcel;
import android.os.Parcelable;

import androidx.annotation.StringDef;

import java.util.ArrayList;
import java.util.List;

public class IStatusBarNotification implements Parcelable {

    /**
     * ID key
     */
    private static final String KEY_ID = "id";


    /**
     * 包名
     */
    private static final String KEY_PACKAGE = "key_package_name";

    /**
     * 样式
     */
    private static final String KEY_STYLE = "key_style";

    /**
     * 标题
     */
    private static final String KEY_TITLE = "key_title";

    /**
     * 内容
     */
    private static final String KEY_CONTENT = "key_content";

    /**
     * 图标
     */
    private static final String KEY_ICON = "key_icon";

    /**
     * 内容点击事件
     */
    private static final String KEY_CONTENT_INTENT = "key_content_intent";

    /**
     * 删除事件
     */
    private static final String KEY_DELETE_INTENT = "key_content_intent";

    /**
     * 子样式
     */
    private static final String KEY_SUB_STYLE = "key_sub_style";

    /**
     * 霸屏
     */
    private static final String KEY_TYRANT = "key_tyrant";

    /**
     * tts 播报
     */
    private static final String KEY_TTS = "key_tts";

    /**
     * 可见即可说
     */
    private static final String KEY_SEE_SAY = "key_see_say";

    /**
     * 提示音
     */
    private static final String KEY_BEEP = "key_beep";

    /**
     * 页面地址
     */
    private static final String KEY_PAGE_URL = "key_page_url";

    /**
     * 标签
     */
    private static final String KEY_TAG = "key_tag";

    /**
     * 时间
     */
    private static final String KEY_WHEN = "key_when";

    /**
     * 事件动作列表
     */
    private static final String KEY_EVENT_ACTION = "key_event_actions";

    /**
     * 可见即可说事件动作列表
     */
    private static final String KEY_SEE_SAY_EVENT_ACTION = "key_see_say_event_actions";

    /**
     * 智能卡片事件动作列表
     */
    private static final String KEY_CARD_EVENT_ACTION = "key_card_event_actions";

    @StringDef({KEY_ID, KEY_PACKAGE, KEY_STYLE, KEY_TITLE, KEY_CONTENT, KEY_ICON, KEY_CONTENT_INTENT, KEY_DELETE_INTENT, KEY_SUB_STYLE,
            KEY_TYRANT, KEY_TTS, KEY_SEE_SAY, KEY_BEEP, KEY_PAGE_URL, KEY_TAG, KEY_WHEN, KEY_EVENT_ACTION, KEY_SEE_SAY_EVENT_ACTION, KEY_CARD_EVENT_ACTION})
    @interface NotificationKey {
    }


    private Bundle extra;

    public IStatusBarNotification() {
    }

    public IStatusBarNotification(int id, String pkgName, int style, String title, String content, String icon, PendingIntent contentIntent, PendingIntent deleteIntent, boolean isTyrant, boolean isTtsOn, boolean seeSay, boolean beep, String pageUrl, List<IStatusBarAction> actions, List<IStatusBarAction> seeSayEventActions, List<IStatusBarAction> smartCardActions, String subStyle, String tag, long when) {
        extra = new Bundle();
        extra.putInt(KEY_ID, id);
        extra.putString(KEY_PACKAGE, pkgName);
        extra.putInt(KEY_STYLE, style);
        extra.putString(KEY_TITLE, title);
        extra.putString(KEY_CONTENT, content);
        extra.putString(KEY_ICON, icon);
        extra.putParcelable(KEY_CONTENT_INTENT, contentIntent);
        extra.putParcelable(KEY_DELETE_INTENT, deleteIntent);
        extra.putBoolean(KEY_TYRANT, isTyrant);
        extra.putBoolean(KEY_TTS, isTtsOn);
        extra.putBoolean(KEY_SEE_SAY, seeSay);
        extra.putBoolean(KEY_BEEP, beep);
        extra.putString(KEY_PAGE_URL, pageUrl);
        extra.putParcelableArrayList(KEY_EVENT_ACTION, (ArrayList<? extends Parcelable>) actions);
        extra.putParcelableArrayList(KEY_SEE_SAY_EVENT_ACTION, (ArrayList<? extends Parcelable>) seeSayEventActions);
        extra.putParcelableArrayList(KEY_CARD_EVENT_ACTION, (ArrayList<? extends Parcelable>) smartCardActions);
        extra.putString(KEY_SUB_STYLE, subStyle);
        extra.putString(KEY_TAG, tag);
        extra.putLong(KEY_WHEN, when);
    }

    protected IStatusBarNotification(Parcel in) {
        extra = in.readBundle(getClass().getClassLoader());
    }

    @Override
    public void writeToParcel(Parcel dest, int flags) {
        dest.writeBundle(extra);
    }

    public int getId() {
        return extra != null ? extra.getInt(KEY_ID, 0) : 0;
    }

    public String getPkgName() {
        return extra != null ? extra.getString(KEY_PACKAGE, "") : "";
    }


    public int getStyle() {
        return extra != null ? extra.getInt(KEY_STYLE, 1) : 1;
    }


    public String getTitle() {
        return extra != null ? extra.getString(KEY_TITLE, "") : "";
    }

    public String getContent() {
        return extra != null ? extra.getString(KEY_CONTENT, "") : "";
    }

    public String getIcon() {
        return extra != null ? extra.getString(KEY_ICON, "") : "";
    }

    public PendingIntent getContentIntent() {
        return extra != null ? (PendingIntent) extra.getParcelable(KEY_CONTENT_INTENT) : null;
    }

    public PendingIntent getDeleteIntent() {
        return extra != null ? (PendingIntent) extra.getParcelable(KEY_DELETE_INTENT) : null;
    }


    public boolean isTyrant() {
        return extra != null && extra.getBoolean(KEY_TYRANT);
    }

    public boolean isTtsOn() {
        return extra != null && extra.getBoolean(KEY_TTS);
    }

    public boolean isSeeSay() {
        return extra != null && extra.getBoolean(KEY_SEE_SAY);
    }

    public boolean isBeep() {
        return extra != null && extra.getBoolean(KEY_BEEP);
    }

    public String getPageUrl() {
        return extra != null ? extra.getString(KEY_PAGE_URL, "") : "";
    }


    public List<IStatusBarAction> getActions() {
        return extra != null ? extra.<IStatusBarAction>getParcelableArrayList(KEY_EVENT_ACTION) : null;
    }

    public List<IStatusBarAction> getSeeSayEventActions() {
        return extra != null ? extra.<IStatusBarAction>getParcelableArrayList(KEY_SEE_SAY_EVENT_ACTION) : null;
    }

    public String getSubStyle() {
        return extra != null ? extra.getString(KEY_SUB_STYLE, "") : "";
    }

    public List<IStatusBarAction> getSmartCardActions() {
        return extra != null ? extra.<IStatusBarAction>getParcelableArrayList(KEY_CARD_EVENT_ACTION) : null;
    }

    public String getTag() {
        return extra != null ? extra.getString(KEY_TAG, "") : "";
    }

    public long getWhen() {
        return extra != null ? extra.getLong(KEY_WHEN, 0) : 0;
    }

    public static Creator<IStatusBarNotification> getCREATOR() {
        return CREATOR;
    }

    @Override
    public int describeContents() {
        return 0;
    }


    public static final Creator<IStatusBarNotification> CREATOR = new Creator<IStatusBarNotification>() {
        @Override

        public IStatusBarNotification createFromParcel(Parcel in) {
            return new IStatusBarNotification(in);
        }

        @Override
        public IStatusBarNotification[] newArray(int size) {
            return new IStatusBarNotification[size];
        }
    };

    @Override
    public String toString() {
        return "IStatusBarNotification{" +
                "id=" + getId() +
                ", pkgName='" + getPkgName() + '\'' +
                ", style=" + getStyle() +
                ", title='" + getTitle() + '\'' +
                ", content='" + getContent() + '\'' +
                ", icon='" + getIcon() + '\'' +
                ", contentIntent=" + getContentIntent() +
                ", deleteIntent=" + getDeleteIntent() +
                ", subStyle='" + getSubStyle() + '\'' +
                ", isTyrant=" + isTyrant() +
                ", isTtsOn=" + isTtsOn() +
                ", seeSay=" + isSeeSay() +
                ", beep=" + isBeep() +
                ", pageUrl='" + getPageUrl() + '\'' +
                ", actions=" + getActions() +
                ", seeSayEventActions=" + getSeeSayEventActions() +
                ", smartCardActions=" + getSmartCardActions() +
                ", tag='" + getTag() + '\'' +
                ", when=" + getWhen() +
                '}';
    }

}
